//
//  OPMovieDetailsViewController.m
//  OnePerson
//
//  Created by xiaofulon on 16/6/12.
//  Copyright © 2016年 BWP. All rights reserved.
//

#import "OPMovieDetailsViewController.h"
#import "OPMovieDetailsHeaderView.h"
#import "OPNoneMessageCell.h"
#import "OPMovieListItem.h"
#import "OPMovieDetails.h"
#import "OPCommentListViewController.h"
#import "OPTicketsGrossView.h"
#import "OPMoviePosterCCell.h"
#import <NYTPhotoViewer/NYTPhoto.h>
#import <NYTPhotoViewer/NYTPhotosViewController.h>
#import "OPMoviePoster.h"
#import "MLBCommonHeaderView.h"
#import "MLBCommonFooterView.h"
#import <MJExtension.h>
#import "OPMovieListItemCCell.h"

typedef NS_ENUM(NSUInteger, OPMovieDetailsType) {
    OPMovieDetailsTypeNone,
    OPMovieDetailsTypeTable,
    OPMovieDetailsTypeStills,
    OPMovieDetailsTypeCast,
};

@interface OPMovieDetailsViewController ()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
/**srollView添加到整个控制器的view*/
@property (strong, nonatomic) UIScrollView *scrollView;
/**内容View添加到整个scrollView上*/
@property (strong, nonatomic) UIView *contentView;
/**头部view*/
@property (strong, nonatomic) OPMovieDetailsHeaderView *headerView;
/**购票等工具view*/
@property (strong, nonatomic) UIView *toolView;
/**买票按钮*/
@property (strong, nonatomic) UIButton *ticketButton;
/**评分按钮*/
@property (strong, nonatomic) UIButton *gradeButton;
/**更多按钮*/
@property (strong, nonatomic) UIButton *moreButton;
/**分享按钮*/
@property (strong, nonatomic) UIView *shareView;
/**分数分享按钮*/
@property (strong, nonatomic) UIButton *scoreShareButton;
/**其他分享按钮*/
@property (strong, nonatomic) UIButton *otherShareButton;
/**故事简介控制器*/
@property (strong, nonatomic) OPCommentListViewController *storyListViewController;
/**评审团意见控制器*/
@property (strong, nonatomic) OPCommentListViewController *reviewListViewController;
/**评价列表控制器*/
@property (strong, nonatomic) OPCommentListViewController *commentListViewController;
/**影片信息View*/
@property (strong, nonatomic) UIView *infoView;
/**影片信息类型*/
@property (strong, nonatomic) UILabel *infoTypeLabel;
/**切换影片信息标签栏按钮*/
@property (strong, nonatomic) UIButton *movieTableButton;
/**切换影片信息剧照按钮*/
@property (strong, nonatomic) UIButton *stillsButton;
/**切换影片信息演职人员按钮*/
@property (strong, nonatomic) UIButton *castButton;
/**影片信息标签栏*/
@property (strong, nonatomic) OPTicketsGrossView *grossView;
/**影片信息剧照栏*/
@property (strong, nonatomic) UICollectionView *moviePosterView;
/**影片信息演职人员栏*/
@property (strong, nonatomic) UITextView *castTextView;
/**影片评分比例标题*/
@property (strong, nonatomic) MLBCommonHeaderView *scoreHeaderView;
/**影片评分比例*/
@property (strong, nonatomic) UILabel *scoreRatioLabel;
/**分享栏右约束*/
@property (strong, nonatomic) MASConstraint *shareViewRightConstraint;
/**故事简介控制器view的高度约束*/
@property (strong, nonatomic) MASConstraint *storiesTableViewHeightConstraint;
/**评审团控制器view的高度约束*/
@property (strong, nonatomic) MASConstraint *reviewsTableViewHeightConstraint;
/**评论列表控制器view的高度约束*/
@property (strong, nonatomic) MASConstraint *commentsTableViewHeightConstraint;

@end

@implementation OPMovieDetailsViewController{
/**tableView初始高度*/
    NSNumber *tableViewInitHeight;
/**模型*/
    OPMovieDetails *movieDetails;
    NSArray *infoButtons;
    NSArray *keywordsLabels;
    NSMutableArray <OPMoviePoster *> *posters;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置导航控制器标题
    self.title = _moviListItem.title;
    // 初始数据
    [self initDatas];
    [self setupViews];
    [self prepareForDisplay];
    [self requestMovieDetails];
}

- (void)initDatas {
    // tableView的高度=header + footer + cell +1;
    tableViewInitHeight = @([MLBCommonHeaderView headerViewHeight] + [MLBCommonFooterView footerViewHeight] + [OPNoneMessageCell cellHeight] + 1);
}

- (void)setupViews {
    self.view.backgroundColor = [UIColor whiteColor];
    // 整个detailView上添加一个scrollView
    _scrollView = ({
        UIScrollView *scrollView = [UIScrollView new];
        scrollView.backgroundColor = self.view.backgroundColor;
        scrollView.delegate = self;
        [self.view addSubview:scrollView];
        // 位置尺寸约束和detailView一样大小
        [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view);
        }];
        
        scrollView;
    });
    // 添加一个内容View
    _contentView = ({
        UIView *view = [[UIView alloc]init];;
        view.backgroundColor = _scrollView.backgroundColor;
        [_scrollView addSubview:view];
        // 尺寸和位置与scrollView一样
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(_scrollView);
            make.width.equalTo(@(SCREEN_WIDTH));
        }];
        
        view;
    });
    // 头部视图,显示电影背景图片和评分等
    _headerView = ({
        OPMovieDetailsHeaderView *headerView = [OPMovieDetailsHeaderView new];
        headerView.backgroundColor = _contentView.backgroundColor;
        [_contentView addSubview:headerView];
        // 位置大小约束,和内容view头部,右边相等,高度为自身高度除以1.808
        [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(_contentView);
            make.height.equalTo(headerView.mas_width).dividedBy(3.0);
        }];
        
        headerView;
    });
    
    // 工具视图
    _toolView = ({
        UIView *view = [UIView new];
        view.backgroundColor = [UIColor whiteColor];
        [_contentView addSubview:view];
        // 高度48,位置在headerView底部,右边和内容View相等
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@48);
            make.top.equalTo(_headerView.mas_bottom);
            make.left.right.equalTo(_contentView);
        }];
        
        view;
    });
    // 购票按钮
    _ticketButton = ({
        UIButton *button = [MLBUIFactory buttonWithImageName:@"movie_ticket_normal" highlightImageName:@"movie_ticket_highlighted" target:self action:@selector(ticketButtonClicked)];
        [button setTitle:@"购票" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithWhite:170 / 255.0 alpha:1] forState:UIControlStateNormal];
        button.titleLabel.font = FontWithSize(12);
        // 将购票按钮添加到_toolView
        [_toolView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.bottom.equalTo(_toolView);
        }];
        
        button;
    });
    // 分享View
    _shareView = ({
        UIView *view = [UIView new];
        [_toolView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@150);
            make.top.bottom.equalTo(_toolView);
            _shareViewRightConstraint = make.right.equalTo(_toolView).offset(150);
        }];
        
        view;
    });
    // 分享评分按钮
    _scoreShareButton = ({
        UIButton *button = [MLBUIFactory buttonWithTitle:@"成绩单分享" titleColor:[UIColor colorWithWhite:170 / 255.0 alpha:1] fontSize:12 target:self action:@selector(scoreShare)];
        [_shareView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@80);
            make.top.left.bottom.equalTo(_shareView);
        }];
        
        button;
    });
    // 其他分享按钮
    _otherShareButton = ({
        UIButton *button = [MLBUIFactory buttonWithTitle:@"其他分享" titleColor:[UIColor colorWithWhite:170 / 255.0 alpha:1] fontSize:12 target:self action:@selector(otherShare)];
        [_shareView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_scoreShareButton.mas_right);
            make.top.right.bottom.equalTo(_shareView);
        }];
        
        button;
    });
    // 更多按钮
    _moreButton = ({
        UIButton *button = [MLBUIFactory buttonWithImageName:@"more_normal" highlightImageName:@"more_highlighted" target:self action:@selector(moreButtonClicked)];
        [_toolView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(button.mas_height).multipliedBy(1);
            make.right.equalTo(_shareView.mas_left);
            make.top.bottom.equalTo(_toolView);
        }];
        
        button;
    });
    // 评分按钮
    _gradeButton = ({
        UIButton *button = [MLBUIFactory buttonWithImageName:@"not_score_normal" selectedImageName:@"not_score_highlighted" target:self action:@selector(gradeButtonClicked)];
        [button setTitle:@"评分" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithWhite:170 / 255.0 alpha:1] forState:UIControlStateNormal];
        button.titleLabel.font = FontWithSize(12);
        [_toolView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@105);
            make.top.bottom.equalTo(_toolView);
            make.right.equalTo(_moreButton.mas_left);
        }];
        
        button;
    });
    
    // 故事简介
    __weak typeof(self) weakSelf = self;
    
    _storyListViewController = [[OPCommentListViewController alloc] initWithCommentListType:OPCommentListTypeMovieStories headerViewType:MLBHeaderViewTypeMovieStory footerViewType:MLBFooterViewTypeMovieStory];
    
    _storyListViewController.finishedCalculateHeight = ^(CGFloat height) {
        weakSelf.storiesTableViewHeightConstraint.equalTo(@(height));
    };
    
    [_contentView addSubview:_storyListViewController.tableView];
    [_storyListViewController.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_toolView.mas_bottom);
        make.left.right.equalTo(_contentView);
        _storiesTableViewHeightConstraint = make.height.equalTo(@0);
    }];
    
    // 评审团短评
    _reviewListViewController = [[OPCommentListViewController alloc] initWithCommentListType:OPCommentListTypeMovieReviews headerViewType:MLBHeaderViewTypeMovieReview footerViewType:MLBFooterViewTypeMovieReview];
    
    _reviewListViewController.finishedCalculateHeight = ^(CGFloat height) {
        weakSelf.reviewsTableViewHeightConstraint.equalTo(@(height));
    };
    [_contentView addSubview:_reviewListViewController.tableView];
    [_reviewListViewController.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_storyListViewController.tableView.mas_bottom).offset(12);
        make.left.right.equalTo(_contentView);
        _reviewsTableViewHeightConstraint = make.height.equalTo(@0);
    }];
    
    // 评论列表
    _commentListViewController = [[OPCommentListViewController alloc] initWithCommentListType:OPCommentListTypeMovieComments headerViewType:MLBHeaderViewTypeMovieComment footerViewType:MLBFooterViewTypeComment];
    
    _commentListViewController.finishedCalculateHeight = ^(CGFloat height) {

        weakSelf.commentsTableViewHeightConstraint.equalTo(@(height));
    };
    
    [_contentView addSubview:_commentListViewController.tableView];
    
    [_commentListViewController.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_reviewListViewController.tableView.mas_bottom).offset(12);
        make.left.right.equalTo(_contentView);
        _commentsTableViewHeightConstraint = make.height.equalTo(@0);
    }];
    
    // 电影详细信息
    _infoView = ({
        UIView *view = [UIView new];
        view.backgroundColor = [UIColor whiteColor];
        [_contentView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@180);
            make.top.equalTo(_commentListViewController.tableView.mas_bottom).offset(12);
            make.left.right.equalTo(_contentView);
        }];
        
        view;
    });
    
    // 演员表Button
    _castButton = ({
        UIButton *button = [MLBUIFactory buttonWithImageName:@"actor_normal" selectedImageName:@"actor_selected" target:self action:@selector(infoButtonClicked:)];
        button.backgroundColor = [UIColor whiteColor];
        button.tag = OPMovieDetailsTypeCast;
        [_infoView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.sizeOffset(CGSizeMake(44, 44));
            make.right.equalTo(_infoView);
            make.top.equalTo(_infoView).offset(4);
        }];
        
        button;
    });
    
    // 剧照Button
    
    _stillsButton = ({
        UIButton *button = [MLBUIFactory buttonWithImageName:@"still_normal" selectedImageName:@"still_selected" target:self action:@selector(infoButtonClicked:)];
        button.backgroundColor = [UIColor whiteColor];
        button.tag = OPMovieDetailsTypeStills;
        [_infoView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(_castButton);
            make.right.equalTo(_castButton.mas_left).offset(-20);
            make.bottom.equalTo(_castButton);
        }];
        
        button;
    });
    
    // 电影TableButton
    _movieTableButton = ({
        UIButton *button = [MLBUIFactory buttonWithImageName:@"plot_normal" selectedImageName:@"plot_selected" target:self action:@selector(infoButtonClicked:)];
        button.backgroundColor = [UIColor whiteColor];
        button.tag = OPMovieDetailsTypeTable;
        [_infoView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(_castButton);
            make.right.equalTo(_stillsButton.mas_left).offset(-20);
            make.bottom.equalTo(_castButton);
        }];
        
        button;
    });
    
    // 将button加入数组
    infoButtons = @[_movieTableButton, _stillsButton, _castButton];
    
    // 显示栏目的label
    _infoTypeLabel = ({
        UILabel *label = [UILabel new];
        label.backgroundColor = [UIColor whiteColor];
        label.textColor = [UIColor colorWithWhite:127 / 255.0 alpha:1];// #7F7F7F
        label.font = FontWithSize(12);
        [_infoView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_movieTableButton);
            make.left.equalTo(_infoView).offset(12);
        }];
        
        label;
    });
    
    // 电影详细信息容器
    UIView *infoContainer = [UIView new];
    infoContainer.backgroundColor = [UIColor whiteColor];
    [_infoView addSubview:infoContainer];
    [infoContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_movieTableButton.mas_bottom).offset(2);
        make.left.bottom.right.equalTo(_infoView);
    }];
    // 电影详细信息容器背景
    UIImageView *infoBGView = ({
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gross_border"]];
        imageView.backgroundColor = [UIColor whiteColor];
        [infoContainer addSubview:imageView];
        // 大小等于信息容器
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(infoContainer);
        }];
        
        imageView;
    });
    // 电影详细信息容器的内容view
    _grossView = ({
        OPTicketsGrossView *view = [OPTicketsGrossView new];
        [infoBGView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(infoBGView).insets(UIEdgeInsetsMake(6, 6, 6, 6));
        }];
        
        view;
    });
    
    // 剧照展示,使用collectionView
    _moviePosterView = ({
        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
        layout.itemSize = CGSizeMake(130, 130);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.minimumLineSpacing = 2;
        UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        collectionView.backgroundColor = [UIColor whiteColor];
        collectionView.dataSource = self;
        collectionView.delegate = self;
        collectionView.scrollsToTop = NO;
        collectionView.showsVerticalScrollIndicator = NO;
        collectionView.showsHorizontalScrollIndicator = NO;
        [collectionView registerClass:[OPMoviePosterCCell class] forCellWithReuseIdentifier:kMLBMoviePosterCCellID];
        [infoContainer addSubview:collectionView];
        [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(infoContainer);
        }];
        
        collectionView;
    });
    // 演员列表View
    _castTextView = ({
        UITextView *textView = [UITextView new];
        textView.backgroundColor = [UIColor whiteColor];
        textView.scrollsToTop = NO;
        textView.selectable = NO;
        textView.editable = NO;
        textView.font = FontWithSize(12);
        [infoContainer addSubview:textView];
        [textView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(infoContainer);
        }];
        
        textView;
    });
    // 评分View
    _scoreHeaderView = ({
        MLBCommonHeaderView *headerView = [[MLBCommonHeaderView alloc] initWithHeaderViewType:MLBHeaderViewTypeScoreRatio];
        [_contentView addSubview:headerView];
        
        [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@([MLBCommonHeaderView headerViewHeight]));
            make.top.equalTo(_infoView.mas_bottom).offset(12);
            make.left.right.equalTo(_contentView);
        }];
        headerView;
    });
    
    //评分比例情况View
    _scoreRatioLabel = ({
        UILabel *label = [UILabel new];
        label.backgroundColor = [UIColor whiteColor];
        label.textColor = [UIColor colorWithWhite:127 / 255.0 alpha:1];// #F7F7F7
        label.font = FontWithSize(14);
        label.numberOfLines = 0;
        [_contentView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_scoreHeaderView.mas_bottom).offset(8);
            make.left.bottom.right.equalTo(_contentView).insets(UIEdgeInsetsMake(0, 12, 8, 12));
        }];
        
        label;
    });
}

// 跳转前准备
- (void)prepareForDisplay {
    _storiesTableViewHeightConstraint.equalTo(tableViewInitHeight);
    _reviewsTableViewHeightConstraint.equalTo(tableViewInitHeight);
    _commentsTableViewHeightConstraint.equalTo(tableViewInitHeight);
    [self switchInfoWithType:OPMovieDetailsTypeNone];
}

- (void)updateViews {
    // 刷新头部View
    [_headerView configureViewWithMovieDetails:movieDetails];
    // 刷新电影详细信息
    [_grossView configureViewWithKeywords:[movieDetails.keywords componentsSeparatedByString:@";"]];
    // 刷新演职人员表
    _castTextView.text = movieDetails.info;
    // 分数为空,则隐藏分数label
    _scoreHeaderView.hidden = IsStringEmpty(movieDetails.score);
    
    _scoreRatioLabel.text = movieDetails.review;
    // 故事介绍
    [_storyListViewController configureViewForMovieDetailsWithItemId:_moviListItem.movieId];
    // 将模型传给故事简介控制器添加为子控制器
    [self addChildViewController:_storyListViewController];
    // 故事简介请求数据
    [_storyListViewController requestDatas];
    //将模型传给评审团意见控制器
    [_reviewListViewController configureViewForMovieDetailsWithItemId:_moviListItem.movieId];
    // 设为子控制器
    [self addChildViewController:_reviewListViewController];
    [_reviewListViewController requestDatas];
    // 评论列表
    [_commentListViewController configureViewForMovieDetailsWithItemId:_moviListItem.movieId];
    [self addChildViewController:_commentListViewController];
    [_commentListViewController requestDatas];
}
// 电影信息切换状态
- (void)switchInfoWithType:(OPMovieDetailsType)type {
    for (UIButton *button in infoButtons) {
        // button的选中状态取决于button的tag是否和type参数相等
        button.selected = button.tag == type;
    }
     // 电影详细信息容器是否隐藏取决于按钮是否选中,选中则不隐藏
    _grossView.hidden = !_movieTableButton.isSelected;
     // 剧照是否隐藏取决于按钮是否选中,选中则不隐藏
    _moviePosterView.hidden = !_stillsButton.isSelected;
     // 演职人员标是否隐藏取决于按钮是否选中,选中则不隐藏
    _castTextView.hidden = !_castButton.isSelected;
    
    // 根据传入的type,决定显示哪个栏目
    switch (type) {
        case OPMovieDetailsTypeNone: {
            _infoTypeLabel.text = @"";
            break;
        }
        case OPMovieDetailsTypeTable: {
            _infoTypeLabel.text = @"一个·电影表";
            
            break;
        }
        case OPMovieDetailsTypeStills: {
            _infoTypeLabel.text = @"剧照";
            // 剧照模型数组存在,且数组元素个数和movieDetails模型的photo数组元素个数不相等,则更新剧照数据
            if (!posters || posters.count != movieDetails.photos.count) {
                [self configurePhotos];
            }
            // 刷新剧照View
            [_moviePosterView reloadData];
            break;
        }
        case OPMovieDetailsTypeCast: {
            _infoTypeLabel.text = @"演职人员";
            break;
        }
    }
}

- (void)configurePhotos {
    posters = @[].mutableCopy;
    // 遍历photo数组,将数组转为poster模型添加到posters模型
    for (NSString *url in movieDetails.photos) {
        OPMoviePoster *poster = [[OPMoviePoster alloc] init];
        poster.imageData = [NSData dataWithContentsOfURL:[url mlb_encodedURL]];
        [posters addObject:poster];
    }
}

#pragma mark - Action
// 购票按钮点击
- (void)ticketButtonClicked {
    
}
// 评分按钮
- (void)gradeButtonClicked {
    
}
// 更多按钮
- (void)moreButtonClicked {
    
}
// 分数分享
- (void)scoreShare {
    
}
// 其他分享
- (void)otherShare {
    
}
// 电影信息按钮点击
- (void)infoButtonClicked:(UIButton *)sender {
    if (!sender.selected) {
        // 切换选中状态
        [self switchInfoWithType:(OPMovieDetailsType)sender.tag];
    }
}

#pragma mark - Network Request
// 获取moviedetails数据
- (void)requestMovieDetails {
    // 发送请求
    [MLBHTTPRequester requestMovieDetailsById:_moviListItem.movieId success:^(id responseObject) {
        if ([responseObject[@"res"] integerValue] == 0) {
            // 字典转模型
            OPMovieDetails *details = [OPMovieDetails mj_objectWithKeyValues:responseObject[@"data"]];
            // 将模型赋值给movieDetails 模型
            movieDetails = details;
            // 刷新数据
            [self updateViews];
            
        } }fail:^(NSError *error) {
            
        }];
}

#pragma mark - UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return movieDetails.photos.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    // 从缓存池中取数据
    return [collectionView dequeueReusableCellWithReuseIdentifier:kMLBMoviePosterCCellID forIndexPath:indexPath];
}

#pragma mark - UICollectionViewDelegateFlowLayout

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
  // 将模型数据传给cell
    [(OPMoviePosterCCell *)cell configureCellWithPostURL:movieDetails.photos[indexPath.row]];
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    // 取消选中状态
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    // 创建photosViewController,用于展示图片
    NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:posters initialPhoto:posters[indexPath.row]];
    // modal出控制器
    [self presentViewController:photosViewController animated:NO completion:NULL];
}

// 控制器销毁时,移除其他控制器
- (void)dealloc {

    [_storyListViewController removeFromParentViewController];
    [_reviewListViewController removeFromParentViewController];
    [_commentListViewController removeFromParentViewController];
}


@end
